<template>
	<u-popup :show="show"  bgColor="transparent" mode="center">
		<view class="grant">
			<view class="text1">非原价销售，请录入实际成交价格</view>
			<view class="price">
				<view>实际成交价</view>
				<view class="input-box"><u--input placeholder="请输入" v-model="price" type="number"
						@confirm="handleConfirm" @blur="handleConfirm"></u--input></view>
				<view>元</view>
			</view>
			<view class="tip">
				<view class="tip-title">提示:</view>
				<view>原价销售,无需录入,直接点“发放”键</view>
				<view>非原价销售，录入实际交易值;</view>
				<view class="tip-title">免费赠送,录入“0”</view>
			</view>
			<view class="grant-btn" style="background: #efefef;color: #666;" v-if="!isShare">发放</view>
			<button open-type="share" :data-obj="shareData" catchtap="share" style="" class="grant-btn" v-if="isShare"
				>发放</button>
			<view class="tip">原价销售直接发放，非原价记得录入实际成交金额</view>
			<image src="../../static/close.png" class="close" @click="handleClose"></image>
		</view>
	</u-popup>
</template>

<script>
	import {
		shareCode,checkCode
	} from '@/api/activationCode.js'
	export default {
		data() {
			return {
				show: false,
				price: null,
				shareData: null,
				id: null,
				isShare: false
			}
		},
		
		
		methods: {
			async handleConfirm() {
				// try {
				// 	const {
				// 		data
				// 	} = await shareCode({
				// 		project_id: this.id,
				// 		real_price: this.price
				// 	})
				// 	this.isShare = true
				// 	this.shareData = data
				// this.$emit('getShareData',{project_id: this.id,real_price: this.price});
				// } catch {
				// 	this.isShare = false
				// }
this.$emit('getPrice',this.price);
			},
			async setModel(id) {
				this.price = null
				this.id = id
				this.show = true
				try {
					const {
						data
					} = await checkCode({
						project_id: this.id,
						real_price: null
					})
					this.isShare = true
					this.shareData = data
					this.$emit('getShareData',this.shareData);
				} catch {
					this.isShare = false
				}
			},
			closeModel(){
				this.price = null
				this.show = false
				this.$parent.getList()
			},
			handleClose(){
				this.price = null
				this.show = false
				this.$parent.getList()
			},
		}
	}
</script>

<style scoped lang="scss">
	.grant {
		width: 600rpx;
		background: #fff;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 50rpx 24rpx 50rpx 24rpx;
		font-size: 30rpx;
		position: relative;
		.close{
			width: 50rpx;
			height: 50rpx;
			position: absolute;
			left: 50%;
			bottom: -100rpx;
			margin-left: -25rpx;
		}

		.grant-btn {
			margin: 32rpx auto;
			width: 300rpx;
			height: 80rpx;
			border-radius: 80rpx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			background-image: linear-gradient(to right, #d17f4e, #cf1730);
		}

		.tip {
			font-size: 26rpx;
			color: #7e8481;
			line-height: 40rpx;

			.tip-title {
				color: #ba7474;
			}
		}

		.price {
			display: flex;
			align-items: center;
			margin-top: 24rpx;
			margin-bottom: 24rpx;

			.input-box {
				margin: 0 24rpx;
				width: 300rpx;
			}
		}

		.text1 {
			color: #ba7474;
			text-align: center;
		}
	}
</style>